namespace Nethouse.Lib.Resolver
{
    public static class ResolverFactory
    {
        private static readonly object locker = new object();

        private static IResolver resolver = null;

        public static IResolver Resolver
        {
            get { return getResolver(); }
            set { setResolver(value); }
        }

        private const string ErrorMessage =
@"Dependency injector required implementing IResolver interface. Sample web implementation in global.asax:

    public class Global : System.Web.HttpApplication
    {
        void Application_Start(object sender, EventArgs e)
        {
            ResolverFactory.Resolver = new UnityResolver();
        }
    }
";

        private static IResolver getResolver()
        {
            if (resolver == null)
            {
                throw new ResolverFactoryException(ErrorMessage);
            }

            return resolver;
        }

        private static void setResolver(IResolver value)
        {
            lock (locker)
            {
                resolver = value;
            }
        }
    }
}